/**
 * 首页图片初始化
 */
var IndexPicture = {
    id: "IndexPictureTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
IndexPicture.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '年龄段', field: 'ageType', align: 'center', valign: 'middle', sortable: true},
        {title: '图片地址', field: 'pictureUrl', align: 'center', valign: 'middle', sortable: true}
    ];
};

/**
 * 检查是否选中
 */
IndexPicture.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        IndexPicture.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加首页图片
 */
IndexPicture.openAddIndexPicture = function () {
    var index = layer.open({
        type: 2,
        title: '添加图片',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/indexPicture/indexPictureAdd'
    });
    this.layerIndex = index;
};

/**
 * 打开查看首页图片详情
 */
IndexPicture.openIndexPictureDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '图片修改',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/indexPicture/indexPictureUpdate/' + IndexPicture.seItem.id
        });
        this.layerIndex = index;
    }
};

$(function () {
    var defaultColunms = IndexPicture.initColumn();
    var table = new BSTable(IndexPicture.id, "/indexPicture/list", defaultColunms);
    table.setPaginationType("client");
    IndexPicture.table = table.init();
});
